let username = localStorage.getItem("uname")

const li1 = document.querySelector(".xtx_navs li:nth-child(1)")
const li2 = document.querySelector(".xtx_navs li:nth-child(2)")
if (username) {
    li1.innerHTML = `<a href="javascript:;"><i class="iconfont icon-user">${username}</i></a>`
    li2.innerHTML = '<a href="javascript:;">退出登录</a>'
} else {
    li1.innerHTML = '<a href="./html/login.html">请先登录</a>'
    li2.innerHTML = '<a href="./html/register.html">免费注册</a>'
}
// 退出登录
li2.addEventListener("click", function () {
    // 退出登录
    //  删除localStroage的uuu的数据
    localStorage.removeItem("uname")
    location.reload(true)
})





let stopstopstop = null
document.querySelector('.left_nav ul').addEventListener('mouseenter', function () {
    document.querySelector('.expansion').style.display = 'block'
})
document.querySelector('.left_nav ul').addEventListener('mouseleave', function () {
    document.querySelector('.expansion').style.display = 'none'
})
document.querySelector('.expansion').addEventListener('mouseenter', function () {
    document.querySelector('.expansion').style.display = 'block'
})
document.querySelector('.expansion').addEventListener('mouseleave', function () {
    document.querySelector('.expansion').style.display = 'none'
})
document.querySelector('.left_nav').addEventListener('mouseover', function (e) {
    const classificationBoxs = document.querySelectorAll('.classification_box')
    if (e.target.tagName === 'LI') {
        document.querySelector('.classification_box.block').classList.remove('block')
        classificationBoxs[e.target.dataset.index].classList.add('block')
    }
})
document.querySelector('.big-box').addEventListener('mouseenter', function () {
    document.querySelector('.left_arrow').style.opacity = 1
    document.querySelector('.right_arrow').style.opacity = 1
    clearInterval(stopstopstop)
})
document.querySelector('.big-box').addEventListener('mouseleave', function () {
    document.querySelector('.left_arrow').style.opacity = 0
    document.querySelector('.right_arrow').style.opacity = 0
    stopstopstop = setInterval(function () {
        document.querySelector('.right_arrow').click()
    }, 2000)
})
document.querySelector('.left_arrow').addEventListener('mouseenter', function () {
    document.querySelector('.left_arrow').style.opacity = 1
    document.querySelector('.right_arrow').style.opacity = 1
    clearInterval(stopstopstop)
})
document.querySelector('.right_arrow').addEventListener('mouseenter', function () {
    document.querySelector('.left_arrow').style.opacity = 1
    document.querySelector('.right_arrow').style.opacity = 1
    clearInterval(stopstopstop)
})
document.querySelector('.dot ul').addEventListener('mouseenter', function () {
    clearInterval(stopstopstop)
    document.querySelector('.left_arrow').style.opacity = 1
    document.querySelector('.right_arrow').style.opacity = 1
})


function fn() {
    const arr = document.querySelectorAll('.big-box>div')
    let num = 0
    const lis = document.querySelectorAll('.dot li')
    document.querySelector('.left_arrow').addEventListener('click', function () {
        num--
        if (num < 0) {
            num = arr.length - 1
        }
        fn1()
    })
    document.querySelector('.right_arrow').addEventListener('click', function () {
        num++
        if (num > arr.length - 1) {
            num = 0
        }
        fn1()
    })
    for (let i = 0; i < arr.length; i++) {
        lis[i].addEventListener('click', function () {
            num = i
            fn1()
        })
    }
    stopstopstop = setInterval(function () {
        document.querySelector('.right_arrow').click()
    }, 2000)
    function fn1() {
        for (let i = 0; i < arr.length; i++) {
            arr[i].style.opacity = 0
        }
        document.querySelector(`.hide${num}`).style.opacity = 1
        document.querySelector('li.highlight').classList.remove('highlight')
        lis[num].classList.add('highlight')
    }
}
fn()
function hotBrand() {
    document.querySelector('.btn1').disabled = true
    document.querySelector('.btn2').style.backgroundColor = '#27ba9b'
    document.querySelector('.btn1').style.cursor = 'not-allowed'
    document.querySelector('.btn2').style.cursor = 'pointer'
    let num = 0
    const width = document.querySelector('.hot_brand .w').offsetWidth
    document.querySelector('.btn2').addEventListener('click', function () {
        document.querySelector('.btn1').disabled = false
        document.querySelector('.btn2').disabled = true
        document.querySelector('.btn1').style.backgroundColor = '#27ba9b'
        document.querySelector('.btn2').style.backgroundColor = '#cccccc'
        document.querySelector('.btn2').style.cursor = 'not-allowed'
        document.querySelector('.btn1').style.cursor = 'pointer'
        num++
        document.querySelector('.roll').style.left = -num * width + 'px'
    })
    document.querySelector('.btn1').addEventListener('click', function () {
        document.querySelector('.btn2').disabled = false
        document.querySelector('.btn1').disabled = true
        document.querySelector('.btn2').style.backgroundColor = '#27ba9b'
        document.querySelector('.btn1').style.backgroundColor = '#cccccc'
        document.querySelector('.btn1').style.cursor = 'not-allowed'
        document.querySelector('.btn2').style.cursor = 'pointer'
        num--
        document.querySelector('.roll').style.left = -num * width + 'px'
    })
}
hotBrand()
function atHome() {
    const arr = [
        {
            url: 'https://yjy-oss-files.oss-cn-zhangjiakou.aliyuncs.com/tuxian/home_goods_cover.jpg',
            title: '3折起狂欢'
        },
        {
            url: 'https://yanxuan-item.nosdn.127.net/01227c93e9098342be591ea57b8953c7.jpg?quality=95&thumbnail=610x610&imageView',
            title: '全场3件8折'
        },
        {
            url: 'https://yanxuan-item.nosdn.127.net/d0176b163973961ed01818d04ee94a06.png?quality=95&thumbnail=610x610&imageView',
            title: '大额优惠 等'
        },
        {
            url: 'https://yanxuan-item.nosdn.127.net/30959f7fcf980de2be0a6e1937938d45.png?quality=95&thumbnail=610x610&imageView',
            title: '3折起狂欢 '
        },
        {
            url: 'https://yanxuan-item.nosdn.127.net/0d7d091a10faf1c22027046f517511cf.png?quality=95&thumbnail=610x610&imageView',
            title: '全场3件8折'
        },
        {
            url: 'https://yjy-oss-files.oss-cn-zhangjiakou.aliyuncs.com/tuxian/kitchen_goods_cover.jpg',
            title: '大额优惠 等'
        }
    ]
    function fnn(a, b) {
        return a + Math.floor((b - a + 1) * Math.random())
    }
    let numm = fnn(0, arr.length - 1)
    document.querySelector('.home_details>div img').src = arr[numm].url
    document.querySelector('.tittle').innerHTML = `${arr[numm].title}`
}
atHome()
 shoppingsss(goodArr)